package 滑动窗口;

/**
 * @ClassName : _209_长度最小的子数组
 * @Author : 骆发茂
 * @Date: 2022/6/8 21:20
 * @Description :
 */
public class _209_长度最小的子数组 {
    public int minSubArrayLen(int target, int[] nums) {
        int left = 0;
        int right = 0;
        int curSum = 0;
        int minLength = 0;
        //最终的最终，满不满足都要这样的限定
        while (right < nums.length) {
            curSum = curSum + nums[right];
            //满足题目要求的时候
            while (curSum >= target) {
                if (right - left + 1 < minLength || minLength == 0) {
                    minLength = right - left + 1;
                }
                //满足的情况下，就要判断能不能缩小
                curSum = curSum - nums[left];
                left++;
            }
            //即不满足curSum >= target的时候，一直right向右增加
            right++;
        }
        return minLength;
    }
}
//leetcode submit region end(Prohibit modification and deletion)